package com.ruoyi.mateproduction.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.mateproduction.domain.MateAsepsis;
import com.ruoyi.mateproduction.domain.MateCleanRecord;
import com.ruoyi.mateproduction.domain.MateHandover;
import com.ruoyi.mateproduction.domain.SterilizationApply;
import com.ruoyi.mateproduction.domain.UnqualifiedHandle;
import com.ruoyi.mateproduction.domain.UnqualifiedNotice;
import com.ruoyi.mateproduction.domain.UnqualifiedReview;
import com.ruoyi.mateproduction.mapper.MateAsepsisMapper;
import com.ruoyi.mateproduction.service.MateAsepsisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author
 * @Version 1.0
 */
@RestController
@RequestMapping("/mateasepsis")
public class MateAsepsisController extends BaseController {

    @Autowired
    MateAsepsisMapper mateAsepsisMapper;

    @Autowired
    MateAsepsisService mateAsepsisService;

    /*
    查询全部的无菌检验记录
     */
    @GetMapping("/selectMateAsepsisList")
    public TableDataInfo selectMateAsepsisList(@RequestParam(value = "beginTime", required = false) String beginTime,
                                               @RequestParam(value = "endTime", required = false) String endTime) {
        startPage();
        MateAsepsis mateAsepsis=new MateAsepsis();
        mateAsepsis.setBeginTime(beginTime);
        mateAsepsis.setEndTime(endTime);
        mateAsepsis.setDeptId(SecurityUtils.getDeptId());
        List<MateAsepsis> asepses = mateAsepsisMapper.selectMateAsepsisList(mateAsepsis);
        return getDataTable(asepses);
    }

    /*
   查询已经做完的无菌检验记录
    */
    @GetMapping("/selectEdit")
    public MateAsepsis selectEdit(@RequestParam(value = "asepsisId", required = false) Long asepsisId) {
        MateAsepsis mateAsepsis = mateAsepsisMapper.selectEdit(asepsisId);
        return mateAsepsis;
    }

    @PostMapping("/addSterilizationApply")
    public AjaxResult addSterilizationApply(@RequestBody SterilizationApply sterilizationApply) {
        sterilizationApply.setDeptId(SecurityUtils.getDeptId());
            int a = mateAsepsisMapper.addSterilizationApply(sterilizationApply);
        if (a > 0) {
            return AjaxResult.success("添加成功");
        } else {
            return AjaxResult.error("添加失败,请联系技术员");
        }
    }

    @GetMapping("/sterilizationApplyList")
    @ResponseBody
    public TableDataInfo sterilizationApplyList(@RequestParam(value = "beginTime", required = false) String beginTime,
                                                @RequestParam(value = "endTime", required = false) String endTime) {

        SterilizationApply sterilizationApply = new SterilizationApply();
        sterilizationApply.setBeginTime(beginTime);
        sterilizationApply.setEndTime(endTime);
        startPage();
        sterilizationApply.setDeptId(SecurityUtils.getLoginUser().getUser().getCompanyId());
        List<SterilizationApply> list = mateAsepsisMapper.sterilizationApplyList(sterilizationApply);
        return getDataTable(list);
    }

    @GetMapping("/selectSterilizationApply")
    public SterilizationApply selectSterilizationApply(@RequestParam(value = "applyId", required = false) Long applyId) {
        SterilizationApply sterilizationApply = mateAsepsisMapper.selectSterilizationApply(applyId);
        return sterilizationApply;
    }

    @PostMapping("/addUnqualifiedHandle")
    public AjaxResult addUnqualifiedHandle(@RequestBody UnqualifiedHandle unqualifiedHandle) {
        unqualifiedHandle.setDeptId(SecurityUtils.getDeptId());
        int a = mateAsepsisMapper.addUnqualifiedHandle(unqualifiedHandle);
        if (a > 0) {
            return AjaxResult.success("添加成功");
        } else {
            return AjaxResult.error("添加失败,请联系技术员");
        }
    }

    @PostMapping("/addUnqualifiedNotice")
    public AjaxResult addUnqualifiedNotice(@RequestBody UnqualifiedNotice unqualifiedNotice) {
        unqualifiedNotice.setDeptId(SecurityUtils.getDeptId());
        int a = mateAsepsisMapper.addUnqualifiedNotice(unqualifiedNotice);
        if (a > 0) {
            return AjaxResult.success("添加成功");
        } else {
            return AjaxResult.error("添加失败,请联系技术员");
        }
    }


    @PostMapping("/addMateHandover")
    public AjaxResult addMateHandover(@RequestBody MateHandover mateHandover) {
        mateHandover.setDeptId(SecurityUtils.getDeptId());
        int a = mateAsepsisService.addMateHandover(mateHandover);
        if (a > 0) {
            return AjaxResult.success("添加成功");
        } else {
            return AjaxResult.error("添加失败,请联系技术员");
        }
    }

    @PostMapping("/addUnqualifiedReview")
    public AjaxResult addUnqualifiedReview(@RequestBody UnqualifiedReview unqualifiedReview) {
        unqualifiedReview.setDeptId(SecurityUtils.getDeptId());
        int a = mateAsepsisService.addUnqualifiedReview(unqualifiedReview);
        if (a > 0) {
            return AjaxResult.success("添加成功");
        } else {
            return AjaxResult.error("添加失败,请联系技术员");
        }
    }


    @GetMapping("/mateHandoverList")
    @ResponseBody
        public TableDataInfo mateHandoverList(@RequestParam(value = "beginTime", required = false) String beginTime,
                                          @RequestParam(value = "endTime", required = false) String endTime) {
        MateHandover mateHandover = new MateHandover();
        mateHandover.setBeginTime(beginTime);
        mateHandover.setEndTime(endTime);
        startPage();
        mateHandover.setDeptId(SecurityUtils.getLoginUser().getUser().getCompanyId());
        List<MateHandover> list = mateAsepsisMapper.mateHandoverList(mateHandover);
        return getDataTable(list);
    }

    @GetMapping("/unqualifiedHandleList")
    @ResponseBody
    public TableDataInfo unqualifiedHandleList(@RequestParam(value = "beginTime", required = false) String beginTime,
                                               @RequestParam(value = "endTime", required = false) String endTime) {
        UnqualifiedHandle unqualifiedHandle = new UnqualifiedHandle();
        unqualifiedHandle.setBeginTime(beginTime);
        unqualifiedHandle.setEndTime(endTime);
        startPage();
        unqualifiedHandle.setDeptId(SecurityUtils.getLoginUser().getUser().getCompanyId());
        List<UnqualifiedHandle> list = mateAsepsisMapper.unqualifiedHandleList(unqualifiedHandle);
        return getDataTable(list);
    }



    @GetMapping("/unqualifiedNoticeList")
    @ResponseBody
    public TableDataInfo unqualifiedNoticeList(@RequestParam(value = "beginTime", required = false) String beginTime,
                                               @RequestParam(value = "endTime", required = false) String endTime) {
        UnqualifiedNotice unqualifiedNotice = new UnqualifiedNotice();
        unqualifiedNotice.setBeginTime(beginTime);
        unqualifiedNotice.setEndTime(endTime);
        startPage();
        unqualifiedNotice.setDeptId(SecurityUtils.getLoginUser().getUser().getCompanyId());
        List<UnqualifiedNotice> list = mateAsepsisMapper.unqualifiedNoticeList(unqualifiedNotice);
        return getDataTable(list);
    }

    @GetMapping("/unqualifiedReviewList")
    @ResponseBody
    public TableDataInfo unqualifiedReviewList(@RequestParam(value = "beginTime", required = false) String beginTime,
                                               @RequestParam(value = "endTime", required = false) String endTime) {
        UnqualifiedReview unqualifiedReview = new UnqualifiedReview();
        unqualifiedReview.setBeginTime(beginTime);
        unqualifiedReview.setEndTime(endTime);
        startPage();
        unqualifiedReview.setDeptId(SecurityUtils.getLoginUser().getUser().getCompanyId());
        List<UnqualifiedReview> list = mateAsepsisMapper.unqualifiedReviewList(unqualifiedReview);
        return getDataTable(list);
    }


    @GetMapping("/selectMateHandover")
    public MateHandover selectMateHandover(@RequestParam(value = "handoverId", required = false) Long handoverId) {
        MateHandover mateHandover = mateAsepsisMapper.selectMateHandover(handoverId);
        return mateHandover;
    }

    @GetMapping("/selectUnqualifiedHandle")
    public UnqualifiedHandle selectUnqualifiedHandle(@RequestParam(value = "handleId", required = false) Long handleId) {
        UnqualifiedHandle unqualifiedHandle = mateAsepsisMapper.selectUnqualifiedHandle(handleId);
        return unqualifiedHandle;
    }


    @GetMapping("/selectUnqualifiedNotice")
    public UnqualifiedNotice selectUnqualifiedNotice(@RequestParam(value = "noticeId", required = false) Long noticeId) {
        UnqualifiedNotice unqualifiedNotice = mateAsepsisMapper.selectUnqualifiedNotice(noticeId);
        return unqualifiedNotice;
    }


    @GetMapping("/selectUnqualifiedReview")
    public UnqualifiedReview selectUnqualifiedReview(@RequestParam(value = "reviewId", required = false) Long reviewId) {
        UnqualifiedReview unqualifiedReview = mateAsepsisMapper.selectUnqualifiedReview(reviewId);
        return unqualifiedReview;
    }


}
